package cp6;

import bean.UserInfo;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

// 管理用户
@WebServlet("/cp6/user")
public class UserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 查询出所有的用户
        List<UserInfo> allUser = null;
        try {
            allUser = DataReadTool.getAllUser();
            // 把用户数据设置到请求对象中
            req.setAttribute("allUser", allUser);
            // 获取到要转发的路径
            RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/views/user.jsp");
            rd.forward(req, resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
